<?php
namespace Common\Service;

class NewsCommentsService extends BaseService
{
    /*
     * id, news_id, uid, status, nickname, create_time
     * content ( 内容 非html ) 存入需要用htmlspecialchars 转
     * referrer 评论时@的用户id对象
     */

    // 状态
    const STATUS_PEDDING = 0;   // 审核 pedding
    const STATUS_PASS    = 1;   // 展示 pass
    const STATUS_DEL     = -1;  // 删除 delete

    //ERROR 错误
    const ERROR_COMMENT = '评论不能为空';

    protected $_validate = array(
        array('content', 'require', self::ERROR_COMMENT, self::MUST_VALIDATE , 'regex', self::MODEL_BOTH),
    );

    protected $_auto = array(
        array('uid', 'intval', self::MODEL_BOTH, 'function'),
        array('content', 'htmlspecialchars', self::MODEL_BOTH, 'function'),
        array('create_time', NOW_TIME, self::MODEL_INSERT),
        array('status', self::STATUS_PEDDING, self::MODEL_INSERT),
    );  

    /**
    *新增评论
    *@param array $comment
    *@return mixed bool|int
    *@author susy<susy.liang@ilongyuan.com.cn>
    */
    public function addComment($comment=array()){

        $comment = $this->create($comment);
        if(!$comment)
            return false;
        $res = $this->add($data);
        return $res;
    }

    /**
     * 获取评论列表
     * @author liubo <liubo@ilongyuan.com.cn>
     */
    public function getByPager($condition, $p = 1, $pager = 10, $order = 'create_time desc') {
        $result = $this->where($condition)->order($order)
                       ->limit(($p-1)*$pager, $pager)->select();
        return $result;
    }
}